import { getLoginUserUsingGet } from "@/api/yonghuxiangguanjiekou"
import {defineStore} from "pinia"
import {ref} from "vue"

export const useLoginUserStore = defineStore("loginUser",()=>{
    const loginUser = ref<API.LoginUserVO>({
        userName:"未登录"
    })

    //远程获取登录用户
    async function fetchLoginUser(){
        const res = await getLoginUserUsingGet()
        if(res.data.code === 0 && res.data.data){
            loginUser.value = res.data.data
        }

        //测试用户登录，3秒后自动登录
        // setTimeout(()=>{
        //     loginUser.value = {
        //         userName:"admin",
        //         id:1
        //     }
        // },3000)
    }

    //设置登录用户
    function setLoginUser(newLoginUser: any){
        loginUser.value = newLoginUser
    }

    //返回登录用户
    return {loginUser,fetchLoginUser,setLoginUser}
})